package io.github.tangwan.jdk8.thread;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author tangwan
 * @version V1.0
 * created on 2021/7/27 10:14
 * @since JDK 1.8
 */
public class MyThread3 implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName());
        return new Random().nextInt(100);
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        for (int i = 0;i < 100;i++){
            FutureTask<Integer> task = new FutureTask<>(new MyThread3());
            new Thread(task).start();
            //Integer result = task.get();
            //System.out.println(Thread.currentThread().getName() + ": " + result);
        }
    }

}
